//
//  BMHCallAndReciveCustomCmd.m
//  BMHVideoMain
//
//  Created by mac on 2017/8/30.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "BMHCallAndReciveCustomCmd.h"

@implementation BMHCallAndReciveCustomCmd
- (instancetype)initNewCallAndReciveWithUserACtion:(int)UserAction AVRoomID:(int)AVRoomID CallSponsor:(NSString *)CallSponsor IMGroupID:(NSString *)IMGroupID IMGroupType:(NSString *)IMGroupType CallTip:(NSString *)CallTip CallType:(int)CallType CallDate:(long)CallDate Sender:(NSString *)Sender SenderPlayURL:(NSString *)SenderPlayURL TargetUrlsArr:(NSArray *)TargetURLS TargetsArr:(NSArray *)TargetsArr  MembersArr:(NSArray *)MembersArr  CallUUID:(NSString *)CallUUID CustomParam:(NSString *)CustomParam {
    if (self = [super init])
    {
        _UserAction = UserAction;
        _AVRoomID = AVRoomID;
        _CallSponsor = CallSponsor;
        _IMGroupID = IMGroupID;
        _IMGroupType = IMGroupType;
        _CallTip = CallTip;
        _CallType = CallType;
        _CallDate = CallDate;
        _Sender = Sender;
        _SenderPlayURL = SenderPlayURL;
        _TargetURLS = TargetURLS;
        _Targets = TargetsArr;
        _Members = MembersArr;
        _CallUUID = CallUUID;
        _CustomParam = CustomParam;


    }
    return self;

}
- (instancetype)initNewCallAndReciveWithUserACtion:(int)UserAction CallType:(int)CallType AVRoomID:(int)AVRoomID  CallDate:(long)CallDate Sender:(NSString *)Sender TargetsArr:(NSArray *)TargetsArr CallUUID:(NSString *)CallUUID {
    if (self = [super init])
    {
        _UserAction = UserAction;
        _AVRoomID = AVRoomID;
        _CallType = CallType;
        _CallDate = CallDate;
        _Sender = Sender;
        _Targets = TargetsArr;
        _CallUUID = CallUUID;
        
        
    }
    return self;

}
- (instancetype)initLiveWaitUserACtion:(int)UserAction CallType:(int)CallType AVRoomID:(int)AVRoomID  CallDate:(long)CallDate Sender:(NSString *)Sender TargetsArr:(NSArray *)TargetsArr CallUUID:(NSString *)CallUUID SenderPlayURL:(NSString *)SenderPlayURL {
    if (self = [super init])
    {
        _UserAction = UserAction;
        _AVRoomID = AVRoomID;
        _CallType = CallType;
        _CallDate = CallDate;
        _Sender = Sender;
        _Targets = TargetsArr;
        _CallUUID = CallUUID;
        _SenderPlayURL = SenderPlayURL;
        
    }
    return self;

}

- (NSData *)NewCallAndReciveSendData {
    //    _UserAction = UserAction;
    //    _AVRoomID = AVRoomID;
    //    _CallSponsor = CallSponsor;
    //    _IMGroupID = IMGroupID;
    //    _IMGroupType = IMGroupType;
    //    _CallTip = CallTip;
    //    _CallType = CallType;
    //    _CallDate = CallDate;
    //    _Sender = Sender;
    //    _SenderPlayURL = SenderPlayURL;
    //    _TargetURLS = TargetURLS;
    //    _Targets = TargetsArr;
    //    _Members = MembersArr;
    //    _CallUUID = CallUUID;
    //    _CustomParam = CustomParam;
    //    _TargetUserID = TargetUserID;
    //    _TargetPushURL = TargetPushURL;
    //    _TargetPlayURL = TargetPlayURL;

    NSMutableDictionary *post = [NSMutableDictionary dictionary];
    [post setObject:@(_UserAction) forKey:@"UserAction"];
    if (_AVRoomID > 0)
    {
        [post setObject:@(_AVRoomID) forKey:@"AVRoomID"];
    }
    if (_CallSponsor && _CallSponsor.length > 0)
    {
        [post setObject:_CallSponsor forKey:@"CallSponsor"];
    }
    if (_IMGroupID && _IMGroupID.length > 0)
    {
        [post setObject:_IMGroupID forKey:@"IMGroupID"];
    }
    if (_IMGroupType && _IMGroupType.length > 0)
    {
        [post setObject:_IMGroupType forKey:@"IMGroupType"];
    }
    if (_CallTip && _CallTip.length > 0)
    {
        [post setObject:_CallTip forKey:@"CallTip"];
    }
    if (_CallType > 0)
    {
        [post setObject:@(_CallType) forKey:@"CallType"];
    }
    if (_CallDate > 0)
    {
        [post setObject:@(_CallDate) forKey:@"CallDate"];
    }
    if (_Sender && _Sender.length > 0)
    {
        [post setObject:_Sender forKey:@"Sender"];
    }
    if (_SenderPlayURL && _SenderPlayURL.length > 0)
    {
        [post setObject:_SenderPlayURL forKey:@"SenderPlayURL"];
    }
    if (_TargetURLS.count > 0)
    {
        [post setObject:_TargetURLS forKey:@"TargetURLS"];
    }
    if (_Targets.count > 0)
    {
        [post setObject:_Targets forKey:@"Targets"];
    }
    if (_Members.count > 0)
    {
        [post setObject:_Members forKey:@"Members"];
    }

    if (_CallUUID && _CallUUID.length > 0)
    {
        [post setObject:_CallUUID forKey:@"CallUUID"];
    }
    if (_CustomParam && _CustomParam.length > 0)
    {
        [post setObject:_CustomParam forKey:@"CustomParam"];
    }


    NSLog(@"NewCallAndReciveSendData ---== %@",post);
    if ([NSJSONSerialization isValidJSONObject:post])
    {
        NSError *error = nil;
        NSData *data = [NSJSONSerialization dataWithJSONObject:post options:NSJSONWritingPrettyPrinted error:&error];
        if(error)
        {
            DebugLog(@"[%@] Post Json Error: %@", [self class], post);
            return nil;
        }

        DebugLog(@"CustomElemCmd content is %@", post);
        return data;
    }
    else
    {
        DebugLog(@"[%@] CustomElemCmd is not valid: %@", [self class], post);
        return nil;
    }

}

@end
